package com.xssn.fjnd.content.controller;


import com.xssn.fjnd.content.req.PhotoREQ;
import com.xssn.fjnd.content.service.IPhotoService;
import com.xssn.fjnd.entities.Photo;
import com.xssn.util.base.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 文章信息表 前端控制器
 * </p>
 *
 * @author 线狮少年
 * @since 2023-08-14
 */
@Api(value = "演出图片管理接口", description = "演出图片管理接口, 提供演出图片的增删改查")
@RestController
@RequestMapping("/photo")
public class PhotoController {

    @Autowired
    private IPhotoService photoService;


    @PreAuthorize("hasAuthority('photo:search')")
    @ApiOperation("根据图片标题和类型查询图片分页列表接口")
    @PostMapping("/search") // localhost:8001/content/photo/search
    public Result search(@RequestBody PhotoREQ req) {
        return photoService.queryPage(req);
    }


    @ApiOperation("查询演出图片详情接口")
    @ApiImplicitParam(name = "id", value = "图片ID", required = true)
    @GetMapping("/{id}")
    public Result view(@PathVariable String id) {

        return Result.ok(photoService.getById(id));
    }

    @PreAuthorize("hasAuthority('photo:edit')")
    @ApiOperation("修改图片信息接口")
    @PutMapping // put 请求
    public Result update(@RequestBody Photo photo) {
        return photoService.updateOrSave(photo);
    }


    @PreAuthorize("hasAuthority('photo:add')")
    @ApiOperation("新增图片信息接口")
    @PostMapping
    public Result save(@RequestBody Photo photo) {
        return photoService.updateOrSave(photo);
    }


    @PreAuthorize("hasAuthority('photo:delete')")
    @ApiImplicitParam(name = "id", value = "演出图片ID", required = true)
    @ApiOperation("删除演出图片接口")
    @DeleteMapping("/{id}")
    public Result delete(@PathVariable("id") String id) {

        return photoService.deleteById(id);
    }


    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "演出图片ID", required = true),
            @ApiImplicitParam(name = "count", value = "点赞数", required = true)
    })
    @ApiOperation("更新点赞数")
    @PutMapping("/thumb/{id}/{count}")
    public Result updataThumhup(@PathVariable("id") String id,
                                @PathVariable("count") int count) {
        return photoService.updateThumhup(id, count);
    }

    @ApiOperation("统计公开的演出图片总记录数（后台首页演出图片数）")
    @GetMapping("/total")
    public Result getArticleTotal() {
        return photoService.getPhotoTotal();
    }

}
